package com.suneast.suneaststore.modules.sort;

import com.suneast.suneaststore.API;
import com.suneast.suneaststore.util.log.LatteLogger;
import com.suneast.suneaststore.util.net.RestClient;
import com.suneast.suneaststore.util.net.callback.ISuccess;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by zestz on 2018/3/27.
 */
final class SortRequestHandler {

    static void requestSortPageData() {
        RestClient.builder()
                .url(API.CATEGORY_PAGE)
                .success((String response) -> {
                    LatteLogger.json("test", response);
                    EventBus.getDefault().post(SortDataParser.parsePage(response));
                })
                .error((code, msg) -> {
                    LatteLogger.e("error", "requestSortPageData error code = " + code
                            + "msg = " + msg);
                })
                .failure(() -> {
                    LatteLogger.e("error", "requestSortPageData failure ");
                })
                .build()
                .post();
    }

    static void requestSortItemData(int id, String type) {
        RestClient.builder()
                .url(API.CATE_CHILD_PAGE)
                .params("id", id)
                .params("type", type)
                .success((String response) -> {
                    LatteLogger.json("test", response);
                    EventBus.getDefault().post(
                            SortDataParser.parseItem(response));
                })
                .error((code, msg) -> {

                })
                .failure(() -> {

                })
                .build()
                .post();
    }
}
